#!/usr/bin/env node

const Koa = require('koa');

const app = new Koa();

app.use(async (ctx,next)=>{ //M-logger
  //const cost = await next();
  //const cost = ctx.response.get('cost');
  next();
  const cost = ctx.cost;
  console.log(`${ctx.method} ${ctx.path} ${cost}ms`)
});

app.use((ctx,next)=>{  //M-ms
  const start = Date.now();
  next();
  const end = Date.now();
  ctx.cost = end-start;
  //ctx.set('cost',end-start);
  //return end-start;
})

app.use((ctx,next)=>{  //M-hello
  ctx.body = 'hello world';
});
app.listen(8080);
